package demo.app;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer;

import javax.sql.DataSource;
import java.util.Arrays;


@EnableAutoConfiguration
@SpringBootApplication
@MapperScan({"demo.projecttask.dao", "demo.common.dao"})
@ComponentScan({"demo.projecttask", "demo.common"})
public class TaskApp {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = new SpringApplicationBuilder(TaskApp.class).web(true).run(args);
        System.out.println("Active profiles: " + Arrays.toString(context.getEnvironment().getActiveProfiles()));
    }

    @Bean
    public MySQLMaxValueIncrementer mySQLMaxValueIncrementer(@Autowired DataSource dataSource){
        MySQLMaxValueIncrementer mySQLMaxValueIncrementer = new MySQLMaxValueIncrementer();
        mySQLMaxValueIncrementer.setIncrementerName("co_idrange");
        mySQLMaxValueIncrementer.setColumnName("id");
        mySQLMaxValueIncrementer.setCacheSize(100);
        mySQLMaxValueIncrementer.setDataSource(dataSource);
        return mySQLMaxValueIncrementer;
    }

}